<?php
/**
 * View.php
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@mygem.org so we can send you a copy immediately.
 *
 * @copyright   Copyright (c) 2012, MyGem <info@mygem.org>
 * @package     MyGem
 */


class MyGem_View
{

    protected $viewPath = '';
    protected $contentsForLayout = '';
    protected $fileLayout = 'layout.php';

    public function __construct($viewPath = '')
    {
        $this->viewPath = $viewPath;
    }

    public function generate($fileContent)
    {
        ob_start();
        if (file_exists($fileContent)) {
            require $fileContent;
        }

        $this->contentsForLayout = ob_get_contents();
        ob_end_clean();

        $output = $this->contentsForLayout;

        $fileLayout = $this->viewPath . $this->fileLayout;
        if (file_exists($fileLayout)) {
            ob_start();
            require $fileLayout;
            $output = ob_get_contents();
            ob_end_clean();
        }

        return $output;
    }

    public function getViewPath()
    {
        return $this->viewPath;
    }

    public function setViewPath($path)
    {
        $this->viewPath = $path;
    }

    public function getFileLayout()
    {
        return $this->fileLayout;
    }

    public function setFileLayout($fileLayout)
    {
        $this->fileLayout = $fileLayout;
    }

}

